<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>客户库盘点管理</title>
	</head>
	<script type="text/javascript">
		$(function(){

			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$('#table').datagrid({
				title:"客户库盘点管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listPageInventory?flag=0',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				frozenColumns:[[
				    {title:'id',field:'id',hidden:true},
				    {title:'仓库id',field:'warehouse_id',hidden:true}
				]],
				columns:[[
					{title:'盘点编号',field:'code',width:100,align:'center'},
					//{title:'盘点仓库',field:'warehouse_name',width:200,align:'center'},
					{title:'盘点日期',field:'operation_date',width:100,align:'center',sortable:true},
					{title:'经办人',field:'person',width:100,align:'center'},
					{title:'盘点说明',field:'remark',width:200,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:70,align:'center'},
					{title:'操作',field:'opt',width:100,align:'center',formatter: function(value,rowData,index){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditInventory(1,'"+rowData.id+"','"+rowData.warehouse_id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteInventory('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.warehouse_id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditInventory(1,'"+rowData.id+"','"+rowData.warehouse_id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.warehouse_id+"');\"/>";
						}
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.CP_INVENTORY_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    	 +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditInventory(2,'"+rowData.id+"','"+rowData.warehouse_id+"');\"/>";
	
					}},
					{title:'导出',field:'excel',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value == "")
						{
							return value;
						}
						return "<input type='button'  style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-excel' title='导出Excel' onclick='ExcelOut("+rowIndex+")'/>";
					}}
				]],view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var inventory_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/warehouse/listInventoryDetail?inventory_id='+inventory_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						nowrap:false,
						rownumbers:true,
						columns:[[
							{title:'盘点仓库',field:'warehouse_name',width:250,align:'center'},
							{title:'盘点客户',field:'customer_name',width:250,align:'center'},
							{title:'产品编号',field:'code',width:150,align:'center'},
							{title:'产品名称',field:'name',width:200,align:'center'},
							{title:'规格/型号',field:'format_type',width:100,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'库存数量',field:'db_num',width:100,align:'center'},
							{title:'实际数量',field:'actually_num',width:100,align:'center'},
							{title:'差异数量',field:'different_num',width:100,align:'center'},
							{title:'备注',field:'remark',width:300,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});

		function shenpi(obj,inventory_id,warehouse_id){
		      var flowBusinessUrl='<%=contextPath %>/springViews/warehouse/addOrEditInventory.jsp?isShow=1&warehouse_id='+warehouse_id+'&inventory_id='+inventory_id+'&type=0';
		      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.CP_INVENTORY_SHENPI%>")+"&businessId="+inventory_id;
		      $(obj).hide();
		      $.ajax({
							type:'POST',
							url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
							dataType:"JSON",
							data:param,
							success:function(rtJson){
								if (rtJson.rtState == '0'){
									openDialogResize(rtJson.rtData.url,1000,800);
								}else{
									warningInfo(rtJson.rtMsrg);
								}
								$(obj).show();
							}
						});
		}
		
		function addOrEditInventory(type,inventory_id,warehouse_id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/warehouse/addOrEditInventory.jsp?callback=rtCallBack&type=0",1000, 800);
			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditInventory.jsp?callback=rtCallBack&type=0&inventory_id='+inventory_id+'&warehouse_id='+warehouse_id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditInventory.jsp?isShow=1&type=0&inventory_id='+inventory_id+'&warehouse_id='+warehouse_id,1000, 800);	
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteInventory(recovery_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deleteInventory",
						data:"inventory_id="+inventory_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function doSearch()
		{
			var firstDay = $('#start_date').datebox('getValue');
			var endDay = $('#end_date').datebox('getValue');
			var searchValue = $('#searchValue').val();
			$('#table').datagrid('load',				
				{
					searchValue:searchValue,
					start_date:firstDay,
					end_date:endDay
				}
			);
		}
		function deleteInventory(inventory_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deleteInventory",
						data:"inventory_id="+inventory_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function ExcelOut(rowIndex){
			var row = $('#table').datagrid("getRows")[rowIndex];
			window.open('<%=contextPath %>/springMVC/excel/dbInventoryExcel?type=0&inventory_id='+row.id);
		}
		</script>
	<script type="text/javascript">
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div  style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addOrEditInventory(0);">新增</a>
			</div>
			<div align="right">
			             开始日期: <input id="start_date" name="start_date" class="easyui-datebox"/>
				结束日期: <input id="end_date" name="end_date" class="easyui-datebox"/>
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="盘点编码/盘点说明"  placeholder="盘点编码/盘点说明"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
